/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package validators;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author robert
 */
public class PasswordValidator  implements Validator{

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        Pattern mask = Pattern.compile("^\\w*(?=\\w*[a-z])(?=\\w*[A-Z])\\w*$");
        String passField = (String)value;
        Matcher matcher = mask.matcher(passField);
        if (!matcher.matches())
        {
            FacesMessage msg = new FacesMessage();
            msg.setDetail("Password must contain one number, one lower case and one upper case letter!");
            msg.setSummary("Password must contain one number, one lower case and one upper case letter!");
            msg.setSeverity(FacesMessage.SEVERITY_ERROR);
            throw new ValidatorException(msg);
        }
    }
    
}
